#ifndef _HASH_H_
#define _HASH_H_

typedef struct _hash_t {
  char *key;
  int hash;
  struct _hash_t *next;
} hash_t;

typedef struct _hash_table_t {
  int size;
  hash_t **table;
} hash_table_t;

/*
 * init_hash_table - initialize a hash table
 *
 * @size size of the hash table, adviced to be a prime
 *
 * return the hash table, or %NULL on error
 */
hash_table_t *init_hash_table(int size);

/*
 * fini_hash_table - deinitialize desired hash table
 *
 * @ht the hash table will be deinitialized
 *
 * no return value
 */
void fini_hash_table(hash_table_t *ht);

/*
 * hash_table_add - add a hash item to hash table
 *
 * @ht the hash table
 * @hi the hash item, hi->key should be pre-initialized
 *
 * return the hash item @hi
 */
hash_t *hash_table_add(hash_table_t *ht, hash_t *hi);

/*
 * hash_table_del - delete a hash item from a hash table
 *
 * @ht the hash table
 * @hi the hash item, hi->key should be pre-initialized
 *
 * return deleted hash item from the table, %NULL if no such item
 */
hash_t *hash_table_del(hash_table_t *ht, char *key);

/*
 * hash_table_index - search the hash table with desired key
 *
 * @ht  the hash table
 * @key the hash key string
 *
 * return hash item match the key, %NULL if no match item exist
 */
hash_t *hash_table_index(hash_table_t *ht, char *key);

#endif
